<?php
require_once('modules/interfaces/itransaction.class.php');

/**
 * MySQL Transaction management. 
 * @author delormef
 *
 */
class MysqlTransaction implements ITransaction{
	private $transaction=null;
	public function __construct(){
		mysql_query("set autocommit=0");
		$this->transaction=mysql_query("start transaction");
	}
	
	/**
	 * (non-PHPdoc)
	 * @see modules/interfaces/ITransaction#isActive()
	 */
	public function isActive(){
		return ($this->transaction!=null);
	}
	/**
	 * (non-PHPdoc)
	 * @see modules/interfaces/ITransaction#commit()
	 */
	public function commit(){
		if($this->transaction!=null){
			mysql_query("commit");
			mysql_query("set autocommit=1");
			$this->transaction=null;
		}
	}
	/**
	 * (non-PHPdoc)
	 * @see modules/interfaces/ITransaction#rollback()
	 */
	public function rollback(){
		if($this->transaction!=null){
			mysql_query("rollback");
			mysql_query("set autocommit=1");
			$this->transaction=null;
		}
	}
}
?>